package Chuong06;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;

public class Bai03 extends JFrame implements Runnable{

	JPanel canvas = new JPanel();
	int hv = 400;
	JButton BT = new JButton("Bất đầu");
	public Bai03(){
		super("Bài 03 - Chương 06");
		setVisible(true);
		setSize(hv+15, hv+40);		
		add(canvas);
		canvas.setBackground(Color.WHITE);
		new Thread(Bai03.this).start();
	}

	public static void main(String[] args) {
		Bai03 frm = new Bai03();		
	}

	@Override
	public void run() {		
		int ct = hv/2;
		int i =ct;
		while(i >= 0){
			int kc = (ct - i) * 2;
			Graphics g = canvas.getGraphics();
			//Trên
			Color c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
			g.setColor(c);
			g.drawLine(i, i, kc + i, i);
			System.out.println("Trên:" + i);
			//Dưới
			c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
			g.setColor(c);
			g.drawLine(i, kc + i, kc + i, kc + i);
			
			//Trái
			c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
			g.setColor(c);
			g.drawLine(i, i, i, i + kc);
			
			//Phải
			c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
			g.setColor(c);
			g.drawLine(i + kc, i, i + kc, i + kc);
			
			i--;
			try{ 
				Thread.sleep(10);
			}
			catch(Exception e){}	
		}
	}

}
